Release 10.1A: OpenEdge Development:
Progress Dynamics Advanced Development
Using addQueryWhere and assignQuerySelection
Use the
addQueryWherefunction and theassignQueryselection function to build more complex and efficient queries.addQueryWhere
The
addQueryWherefunction takes threeINPUTparameters:If you do not specify the buffer name parameter, then you must qualify the field names in your
WHEREclause with their table names in order to allow the function to build theWHEREclause most efficiently, with each phrase appended to the query join clause where that table appears in the join sequence. The SDO propertyQueryStringstores successive changes to theWHEREclause. This property is stored in the client SDO (if the SDO is split between client and server). WhenopenQueryis run, it checks to see if theQueryStringproperty has a value, and if so, sends it to the server, prepares the database query using that value, and then opens the query. This allows your code to build up a complexWHEREclause efficiently, without preparing or opening the intermediate steps (or even sending them to the server) until the signal is given to open the database query.For example, if you create a new SmartWindow called waddwhere.w, you can use the
addQueryWherefunction to allow filtering of a query. To show how the function operates on a joined query, use a SmartDataObject called djoin.w, which joins “EACH Order, Customer OF Order, SalesRep OF Order”. There is a field called Where-Field in the window that you can use to enter a newWHEREclause phrase, with this trigger code:
AssignQuerySelection and removeQuerySelection
The
assignQuerySelectionandremoveQuerySelectionfunctions are designed to make it easy to map values to fields to create aWHEREclause. These functions are especially suited to application procedures, such as a Query By Form, where you enter a value for one or more fields and expect to see database records matching those values.The first of these functions,
assignQuerySelection, takes threeINPUTparameters:
- A comma-separated list of
fieldnamesto be used in theWHEREclause.- A
CHR(1)-delimited list of values for those fields.- An operator or list of operators to apply to the values. If this third parameter is not specified,
EQUALSis the default. If a single operator is supplied for that parameter, it is applied to all field-value pairs. The special value ofEQ/BEGINSmeans that numeric fields should use theEQoperator, andCHARACTERfields theBEGINSoperator. Or a comma-separated list of operators can be supplied, and each operator in the list is applied to the corresponding field-value pair.For example, you can use a SmartWindow called wselection.w to apply these functions to a
CustomerSDO. You can enter a list of fields in the Column-Field, and you can enter a list of values in the Values-Field. To simplify the example enter the values as a comma-separated list and replace the commas withCHR(1)when you use the list. Enter an operator in the third field. The leave trigger puts the pieces together and opens the SDO query with the values specified, as shown:
There is also a Remove-Field, which allows you to name a field that contains a
WHEREclause fragment that you want to remove. Remove-Field executes theremoveQuerySelectionfunction, which takes twoINPUTparameters: the name of the field and the operator associated with that field, as shown:
You can test how these functions work by entering two field names, values for those fields, and an operator.
![]()
To test this window:
Note that one feature of the
assignQuerySelectionfunction is that it handles quotation marks properly. The values entered into the list must not be in quotation marks. It is easier to assemble a list of values that come out of a list of fill-in fields for different database fields without having to add code to put quotes around those that need it (CHARACTERandDATEtypes);assignQuerySelectiondoes this for you. Note thatassignQuerySelectionalso identifies the table that each field comes from and qualifies the field name references. If there is a join involved, it also distributes the where clause phrases properly for maximum efficiency.Typing Address into the Remove field runs
removeQuerySelection, which removes that part of theWHEREclause from the query, as shown:
![]()
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |